/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.view;

import com.model.Anggota;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.model.Perpustakaan;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PanelTambahAnggota extends JPanel {

    private JLabel labelKodeAnggota;
    private JTextField textKodeAnggota;
    private JLabel labelNama;
    private JTextField textNama;
    private JButton tombolSimpan;
    private JButton tombolBatal;

    public PanelTambahAnggota() {
        this.setSize(400, 300);
        setLayout(null);

        labelKodeAnggota = new JLabel("Kode Anggota ");
        labelKodeAnggota.setBounds(50, 50, 150, 40);
        add(labelKodeAnggota);

        textKodeAnggota = new JTextField(20);
        textKodeAnggota.setBounds(150, 60, 150, 20);
        add(textKodeAnggota);

        labelNama = new JLabel("Nama Anggota ");
        labelNama.setBounds(50, 80, 150, 40);
        add(labelNama);

        textNama = new JTextField(20);
        textNama.setBounds(150, 90, 150, 20);
        add(textNama);

        tombolSimpan = new JButton("SIMPAN ");
        tombolSimpan.setBounds(100, 150, 100, 20);
        add(tombolSimpan);
        tombolSimpan.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tombolSimpanAction();
            }
        });

        tombolBatal = new JButton("Batal");
        tombolBatal.setBounds(220, 150, 100, 20);
        add(tombolBatal);
        tombolBatal.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tombolBatalAction();
            }
        });

        setVisible(true);
    }

    public void tombolSimpanAction() {
         Anggota agg = new Anggota();
        agg.setIdAnggota(textKodeAnggota.getText());
        agg.setNama(textNama.getText());
        Perpustakaan.tambahAnggota(agg);
        Perpustakaan.tambahTabelAnggota(agg);
        JOptionPane.showMessageDialog( this,"Id Anggota : "+agg.getIdAnggota() +
                                          "\nNama       : "+agg.getNama());
    }

    public void tombolBatalAction() {
        System.exit(0);
    }
}
